<template>
  <Modal
    title="申请页面"
    :value="value"
    :mask-closable="true"
    :footer-hide="true"
    @input="$emit('input', $event)"
  >
    <Form
      ref="formLkyApply"
      :model="formLkyApply"
      :rules="ruleValidate"
      label-position="right"
      :label-width="80"
    >
      <FormItem label="表名" prop="name">
        <Input type="text" v-model="formLkyApply.file_name" placeholder="表名" readonly/>
      </FormItem>
     
      <FormItem label="申请理由" prop="remark_info">

        <Input type="text" v-model="formLkyApply.remark_info"  placeholder="申请理由"/>
      </FormItem>

      </FormItem>

      <FormItem>
        <Button type="primary" @click="handleSubmit('formLkyApply')">提交</Button>
        <Button @click="handleReset('LkyApplyInfo')" style="margin-left: 8px">重置</Button>
      </FormItem>

    </Form>
  </Modal>
</template>
<script>
import {save} from '@/api/lky/lkyApply'
import {createModelObj, coverFormProps, getToken} from '@/libs/util'
// 学院查询、专业查询
import {queryAll} from '@/api/lky/lkyCollege'
import {queryAllM} from '@/api/lky/lkyMajor'

export default {
  name: 'Add',
  props: {
    value: {
      type: Boolean,
      default: false
    },
    LkyApply: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      collegeList: [],
      coid: '',
      majorList: [],
	  remark_info:[],
      formLkyApply: {
        fife_name: '',
        remark_info: '',
        times: '',
        count: '',
        start_time: '',
        end_time: '',
		fid:'',
		
      },
	  lkyApply :{
		  remark_info: '',
		  },
	 
      LkyApplyInfo: {
        uid: '',
        fid: '',
        remark_info: ''
      },

      ruleValidate: {
        remark_info: [
          {required: true, message: '该值不能为空', trigger: 'blur'},
          {type: 'string', max: 200, message: '长度最长为200', trigger: 'blur'}
        ]
      }
    }
  },

  methods: {
    onOpenChangeCollege () {
      queryAll().then(res => {
        this.collegeList = res.data
        this.formLkyApply.mid = ''
      })
    },
    onOpenChangeMajor (coid) {
      queryAllM({ 'coid': this.coid }).then(res => {
        this.majorList = JSON.parse(JSON.stringify(res.data))
      })
    },
	
    handleSubmit (name) {
		this.LkyApplyInfo.remark_info = this.formLkyApply.remark_info
      this.$refs[name].validate(valid => {
		  
        if (valid) {
          save(Object.assign({}, createModelObj(this.LkyApplyInfo, 'lkyApplyRecord'))).then(
            res => {
              if (res) {
                this.$emit('addRow', res.row)
                this.$emit('input', false)
                this.handleReset(name)
              }
            }
          )
					
        } else {
          this.$Message.error('验证失败!')
        }
      })
    },
    handleReset (name) {
	  this.LkyApply.remark_info = ''
      this.$refs[name].resetFields()
    }
  },
  watch: {
    value: function (val, oldVal) {
      this.$refs.formLkyApply.resetFields()
	  this.LkyApplyInfo.fid = this.LkyApply.fid
	  this.LkyApplyInfo.uid = getToken()
      coverFormProps(this.formLkyApply, this.LkyApply)
    },
   
    LkyApply (n) {
      if (n != null) {
		this.formLkyApply = n
        this.coid = n.id2
        this.onOpenChangeMajor()
      }
    }
  },
  // 这里
  mounted () {
    this.onOpenChangeCollege()
    this.onOpenChangeMajor()
  }

 
}
</script>
